package com.chance.cc.crawler.development.bootstrap.womai;

import com.alibaba.fastjson.JSON;
import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.downloader.proxy.Proxy;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRecord;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;

/**
 * @ClassName womai
 * @Description TODO
 * @Author songding
 * @Date 2021/10/17 17:26
 * @Version 1.0
 * 中粮我买
 **/
public class WomaiStart {
    public static final String domain = "womai";

    public static void main(String[] args) {

        auto();
    }
    private static Proxy proxy = new Proxy();
    static{
        proxy.setHost("http-dyn.abuyun.com");
        proxy.setPort(9020);
        proxy.setUsername("H7307T4706B25G4D");
        proxy.setPassword("05B4877CC39192C0");

    }
    public static void auto(){
        String site = "search";
        String url = "https://sh.womai.com";
        CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpConfig(HttpConfig.me(domain))
                .httpUrl(url)
                .recordKey(url)
                .proxy(proxy)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.comment)
                .releaseTime(System.currentTimeMillis())
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*50,null))
                .build();
        record.tagsCreator().bizTags().addDomain(domain);
        record.tagsCreator().bizTags().addSite(site);

        record.tagsCreator().bizTags().addCustomKV("q","牛奶");

        CrawlerRecord filterRecord = new CrawlerRecord();
        filterRecord.setFilter(CrawlerEnum.CrawlerRecordFilter.dateRange);
        filterRecord.addFilterInfo(FilterUtils.dateRangeFilterInfo(24,null));
        record.tagsCreator().bizTags().addCustomKV("comment_record_filter_info", JSON.toJSONString(filterRecord));

        DevCrawlerController.builder()
                .triggerInfo(domain,domain,System.currentTimeMillis(),domain)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                .consoleResultPipeline()
                .requestRecord(record)
                .build("com.chance.cc.crawler.development.scripts.womai")
                .start();

    }




  /*  @Test
    public void test(){

        String encode = null;
        try {
            encode = URLEncoder.encode("月饼","gbk");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String doc = null;
        try {
            doc = URLDecoder.decode("%C5%A3%C4%CC","gbk");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        System.out.println(encode);
        System.out.println(doc);
    }*/
}
